home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
et
/
et3_0-a1.lha
/
et3
/
src
/
Alert.C
< prev
next >
Wrap
C/C++ Source or Header
|
1992-08-24
|
4KB
|
206 lines
#ifdef __GNUG__
#pragma implementation
#endif
#include "Alert.h"
#include "Class.h"
#include "Env.h"
#include "ImageItem.h"
#include "Buttons.h"
#include "CheapText.h"
#include "StaticTView.h"
#include "StyledText.h"
#include "OrdColl.h"
#include "ObjArray.h"
#include "Window.h"
#include "Expander.h"
#include "BorderItems.h"
static u_short NoteBits[]= {
# include "images/note.image"
};
static u_short CautionBits[]= {
# include "images/caution.image"
};
static u_short StopBits[]= {
# include "images/stop.image"
};
static u_short SunBits[]= {
# include "images/sun.image"
};
static u_short ErrorBits[]= {
# include "images/error.image"
};
SmartBitmap gNote(Point(64, 52), NoteBits),
gCaution(Point(64, 52), CautionBits),
gStop(64, StopBits),
gSun("sun.xpm"), //gSun(64, SunBits),
gError(64, ErrorBits);
ONEXIT(Alert)
{
if (Alert::alerts) {
Alert::alerts->FreeAll();
SafeDelete(Alert::alerts);
}
}
//---- Alert -------------------------------------------------------------------
NewMetaImpl(Alert,Dialog, (TP(text), TP(textview), TP(image), TP(buttons), TP(alerts)));
ObjArray *Alert::alerts;
Alert::Alert(AlertType at, byte *message, Bitmap *va_(bm), ...) : Dialog()
{
va_list ap;
OrdCollection *ol;
va_start(ap,va_(bm));
if (message) {
text= new CheapText(message);
textview= new StaticTextView((View*)0,
Rectangle(gSysFont->Width('n')*40, cFit), text);
if (va_(bm))
image= new ImageItem(va_(bm), 0);
if (at == eAlertMessage)
image= textview;
else
image= new HBox(gPoint10, eVObjVTop, image, textview, 0);
ol= new OrdCollection;
char *s;
for (int i= 0; s= va_arg(ap, char*); i++)
ol->Add(new ActionButton(va_arg(ap, int), s, i == 0));
buttons= new HBox(20, (VObjAlign)(eVObjVBase|eVObjHEqual|eVObjHExpand), ol);
}
va_end(ap);
}
Alert::~Alert()
{
SafeDelete(text);
}
VObject *Alert::DoMakeContent()
{
return new Matte(new VBox(20, eVObjHLeft, image, buttons, 0));
}
int Alert::Show(char* va_(fmt), ...)
{
int code;
va_list ap;
va_start(ap,va_(fmt));
code= ShowV(va_(fmt), ap);
va_end(ap);
return code;
}
int Alert::ShowV(char *fmt, va_list ap)
{
return ShowV(gSysFont, fmt, ap);
}
int Alert::ShowV(Font *fp, char *fmt, va_list ap)
{
char *buf= strvprintf(fmt, ap);
SafeDelete(text);
text= new StyledText(fp, buf);
SafeDelete(buf);
textview->SetText(text);
textview->SetExtent(Point(textview->GetExtent().x, cFit));
return Dialog::ShowUnderMouse();
}
void Alert::InspectorId(char *buf, int sz)
{
if (textview)
textview->InspectorId(buf, sz);
else
Dialog::InspectorId(buf, sz);
}
static Alert *GetAlert(AlertType at)
{
Alert *al= 0;
if (Alert::alerts == 0)
Alert::alerts= new ObjArray((int)eAlertError);
if ((al= (Alert*) Alert::alerts->At(at)) == 0) {
switch (at) {
case eAlertNote:
al= new Alert(at, (byte*) "note", gNote, "OK", cIdOk, 0);
break;
case eAlertCaution:
al= new Alert(at, (byte*) "Caution", gCaution,
"Yes", cIdYes,
"No", cIdNo,
"Cancel", cIdCancel, 0);
break;
case eAlertStop:
al= new Alert(at, (byte*) "Stop", gStop,
"Yes", cIdYes,
"No", cIdNo,
"Cancel", cIdCancel, 0);
break;
case eAlertSun:
al= new Alert(at, (byte*) "Message", gSun, "Ok", cIdOk, 0);
break;
case eAlertError:
if (Env::GetValue("Application.DebugButtonInAlert", FALSE))
al= new Alert(at, (byte*) "Error", gError,
"Ignore", cIdIgnore,
"Dump Core", cIdAbort,
"Debug", cIdInspect, 0);
else
al= new Alert(at, (byte*) "Error", gError,
"Ignore", cIdIgnore,
"Dump Core", cIdAbort, 0);
break;
case eAlertMessage:
al= new Alert(at, (byte*) "Message", 0, "Ok", cIdOk, 0);
break;
}
if (al)
Alert::alerts->AtPut(at, al);
}
return al;
}
int ShowAlert(AlertType at, char* va_(fmt), ...)
{
int code= 0;
va_list ap;
Alert *al;
va_start(ap, va_(fmt));
al= GetAlert(at);
if (al)
code= al->ShowV(va_(fmt), ap);
va_end(ap);
return code;
}
int ShowAlert(AlertType at, Font *fp, char* va_(fmt), ...)
{
int code= 0;
va_list ap;
Alert *al;
va_start(ap, va_(fmt));
al= GetAlert(at);
if (al)
code= al->ShowV(fp, va_(fmt), ap);
va_end(ap);
return code;
}